package com.csyf.manager.controller;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import com.csyf.manager.channel.base.PaymentVo;
import com.csyf.manager.common.CommonConst;
import com.csyf.manager.entity.*;
import com.csyf.manager.exception.ApiValidateException;
import com.csyf.manager.service.*;
import com.csyf.manager.service.impl.RedisService;
import com.csyf.manager.service.impl.SysAgentBalanceBiz;
import com.csyf.manager.utils.*;
import com.csyf.manager.utils.page.JqGridVo;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.LockedAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @Author: Enzo
 * @Date: 2018/4/11 11:18
 */
@Slf4j
@Controller
//@RequestMapping(value = "/boss")
public class BossController {

    @Autowired
    private OrderService orderService;


    @Autowired
    private PayMentBiz payMentBiz;


    @Autowired
    private SysMerchBiz sysMerchBiz;


    @Autowired
    private SysTradeSummaryService sysTradeSummaryService;

    @Autowired
    private SysTradeTypeBiz sysTradeTypeBiz;

    @Autowired
    private SysChannelBiz sysChannelBiz;

    @Autowired
    private SysPaymentChannelBiz sysPaymentChannelBiz;


    @Autowired
    private ProxyQueryBiz proxyQueryBiz;

    @Autowired
    private SysAgentBalanceBiz sysAgentBalanceBiz;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    private SysChannelAttrBiz sysChannelAttrBiz;


    @Autowired
    private SysUserService sysUserService;

    @Autowired
    private SysMenuService sysMenuService;


    @Autowired
    private SysAgentService sysAgentService;


    @Autowired
    private RedisService redisService;


    /**
     * 跳转首页
     **/
    @RequestMapping(value = {"/", "/index"})
    public String index(HttpServletRequest request) {
        return "index/index";
    }

    @GetMapping(value = "login")
    public String login() {
        return "system/login";
    }


    /**
     * 提交登录
     *
     * @param request
     * @param username
     * @param password
     * @param verification
     * @param rememberMe
     * @return
     */
    @ResponseBody
    @PostMapping("/login")
    public ResultEntity login(HttpServletRequest request, String username, String password, String verification,
                              @RequestParam(value = "rememberMe", defaultValue = "0") Integer rememberMe, String vcode) {
        //校验验证码
        String rightCode = (String) request.getSession().getAttribute(CommonConst.KAPTCHA_SESSION_KEY);
        if (StringUtils.isNotBlank(verification) && StringUtils.isNotBlank(rightCode) && verification.equals(rightCode)) {
            //验证码通过
        } else {
            return ResultUtli.DEFAULT_ERROR("验证码错误！");
        }


        SysUser userInfo = sysUserService.selectByUsername(username);

        if (null == userInfo) {
            return ResultUtli.DEFAULT_ERROR("用户不存在，请重新输入");
        }
        //获取商户预留手机号
        String reservedPhone = "";
        if (userInfo.getUserId() == 1) {
            reservedPhone = "15701510275;18310139974;15701276032";
        } else {
            if ("2".equals(userInfo.getUserType())) {
                SysAgent sysAgent = sysAgentService.queryAgentByUserId(userInfo.getUserId());
                reservedPhone = sysAgent.getAgentPhone();
            } else if ("3".equals(userInfo.getUserType())) {
                SysMerchant agent = sysMerchBiz.queryAgentByUserId(userInfo.getUserId());
                reservedPhone = agent.getMerchPhone();
            }
        }

        String loginSmsVerifyCode = redisService.getLoginSmsVerifyCode(reservedPhone);
        if (null == loginSmsVerifyCode || StringUtils.isBlank(loginSmsVerifyCode)) {
            return ResultUtli.DEFAULT_ERROR("请先获取验证码");
        }

        if (StringUtils.isNotBlank(vcode) && StringUtils.isNotBlank(loginSmsVerifyCode) && vcode.equals(loginSmsVerifyCode)) {
            //验证码通过
        } else {
            return ResultUtli.DEFAULT_ERROR("手机验证码错误！");
        }


        UsernamePasswordToken token = new UsernamePasswordToken(username, password);

        try {
            token.setRememberMe(1 == rememberMe);
            Subject subject = SecurityUtils.getSubject();
            //登录，进行身份验证操作
            subject.login(token);
        } catch (LockedAccountException e) {
            token.clear();
            return ResultUtli.DEFAULT_ERROR("账号已经被锁定不能登录，请联系管理员！");
        } catch (AuthenticationException e) {
            token.clear();
            return ResultUtli.DEFAULT_ERROR("用户名或者密码错误！");
        }

        //更新登录时间
        sysUserService.updateLastLoginTime((SysUser) SecurityUtils.getSubject().getPrincipal());
        return ResultUtli.DEFAULT_SUCCESS("登录成功！", null);
    }

    /**
     * 获取当前登录用户的菜单
     **/
    @PostMapping("/menu")
    @ResponseBody
    public List<SysMenu> getMenus() {
        SysUser user = (SysUser) SecurityUtils.getSubject().getPrincipal();
        List<SysMenu> menuList = sysMenuService.selectMenuByUserId(user.getUserId());
        return menuList;
    }

    @RequestMapping(value = "/logout")
    @ResponseBody
    public ResultEntity logout() {
        return ResultUtli.DEFAULT_SUCCESS("成功", null);
    }


    @GetMapping(value = "boss_login")
    public String loginget() {
        return "boss/login";
    }

    @GetMapping(value = "view/{pageName}")
    public String viewPage(@PathVariable(value = "pageName") String pagename) {
        return "boss/" + pagename;
    }

    @GetMapping(value = "other/{pageName}")
    public String viewotherPage(@PathVariable(value = "pageName") String pagename) {
        return "other/" + pagename;
    }


    @ResponseBody
    @PostMapping(value = "orderDataList")
    public JqGridVo orderDataList(SysTrade vo, Integer rows, Integer page) {

        return orderService.queryOrderByUserId(vo, page, rows);
    }


    /*首页echart图表显示*/
    @ResponseBody
    @PostMapping(value = "sumChart")
    public ReturnData sumChart() {
        return sysTradeSummaryService.buildChartBydate();
    }


    /**
     * 收单流水汇总
     *
     * @return
     */
    @ResponseBody
    @PostMapping(value = "sumTradeFlowByDate")
    public ReturnData sumTradeFlowByDate() {
        ReturnData returnData = new ReturnData();
        returnData.setCode(0);
        returnData.setMsg("查询成功");

        TradeFlowVo tradeFlowVo = sysTradeSummaryService.sumTradeFlowBydate();

        Map<String, String> tradeMap = new HashMap<>();
        tradeMap.put("todayTotalFee", tradeFlowVo.getTodayTotalFee().setScale(2, BigDecimal.ROUND_HALF_UP).toString());
        tradeMap.put("todayProfit", tradeFlowVo.getTodayProfit().setScale(2, BigDecimal.ROUND_HALF_UP).toString());
        tradeMap.put("todayHandlingFee", tradeFlowVo.getTodayHandlingFee().setScale(2, BigDecimal.ROUND_HALF_UP).toString());
//        tradeMap.put("totalFee", tradeFlowVo.getTotalFee().setScale(2, BigDecimal.ROUND_HALF_UP).toString());
//        tradeMap.put("profit", tradeFlowVo.getProfit().setScale(2, BigDecimal.ROUND_HALF_UP).toString());
//        tradeMap.put("handlingFee", tradeFlowVo.getHandlingFee().setScale(2, BigDecimal.ROUND_HALF_UP).toString());

        returnData.setData(tradeMap);
        return returnData;
    }


    @ResponseBody
    @PostMapping(value = "balanceDataList")
    public JqGridVo balanceDataList(SysAgentBalance vo, Integer rows, Integer page) {

        return sysAgentBalanceBiz.queryOrderByUserId(vo, page, rows);
    }


    @ResponseBody
    @PostMapping(value = "paymentDataList")
    public JqGridVo paymentDataList(SysPayment vo, Integer rows, Integer page) {

        return payMentBiz.queryOrderByUserId(vo, page, rows);
    }

    @ResponseBody
    @PostMapping(value = "agentDataList")
    public JqGridVo agentDataList(SysMerchant vo, Integer rows, Integer page) {

        return sysMerchBiz.querydata(vo, page, rows);
    }


    @ResponseBody
    @PostMapping(value = "agentmchdayList")
    public JqGridVo agentmchdayList(SysTradeSummary vo, Integer rows, Integer page) {

        return sysTradeSummaryService.querydataByAgent(vo, page, rows);
    }

    @ResponseBody
    @PostMapping(value = "agentmchcurdayList")
    public JqGridVo agentmchcurdayList(SysTradeSummary vo, Integer rows, Integer page) {
        return sysTradeSummaryService.queryCurDateTrade(vo, page, rows);
    }

    /**
     * 删除代理商
     *
     * @param agentId
     * @return
     */
    @ResponseBody
    @PostMapping(value = "deleteAgentById")
    public ResultEntity deleteAgent(Long agentId) {
        SysMerchant sysAgent = sysMerchBiz.queryAgentById(agentId);
        if (sysAgent != null && "boss".equalsIgnoreCase(sysAgent.getMerchAccount())) {
            return ResultUtli.ERRO(10, "管理员账户不能删除！", null);
        }

        if (1 == sysAgent.getMerchStatus()) {
            return ResultUtli.ERRO(10, "请先停用该代理商！", null);
        }

        int flag = sysMerchBiz.deleteById(agentId);
        if (flag > 0) {
            return ResultUtli.DEFAULT_SUCCESS("删除成功", null);
        } else {
            return ResultUtli.DEFAULT_SUCCESS("删除失败", null);
        }
    }

    @ResponseBody
    @PostMapping(value = "startAgent")
    public ResultEntity startAgent(Long agentId) {
        try {
            SysMerchant sysAgent = sysMerchBiz.queryAgentById(agentId);
            if (sysAgent != null && "boss".equalsIgnoreCase(sysAgent.getMerchAccount())) {
                return ResultUtli.ERRO(10, "管理员账户不能更改！", null);
            }

            sysMerchBiz.startAgent(agentId);
            return ResultUtli.DEFAULT_SUCCESS("启用成功", null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtli.ERRO(10, "启用失败", null);
        }
    }

    @ResponseBody
    @PostMapping(value = "stopAgent")
    public ResultEntity stopAgent(Long agentId) {
        try {
            SysMerchant sysAgent = sysMerchBiz.queryAgentById(agentId);
            if (sysAgent != null && "boss".equalsIgnoreCase(sysAgent.getMerchAccount())) {
                return ResultUtli.ERRO(10, "管理员账户不能更改！", null);
            }

            sysMerchBiz.stopAgent(agentId);
            return ResultUtli.DEFAULT_SUCCESS("停用成功", null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtli.ERRO(10, "停用失败", null);
        }
    }


    /**
     * 收益列表
     *
     * @param vo
     * @param rows
     * @param page
     * @return
     */
    @ResponseBody
    @PostMapping(value = "profitList")
    public JqGridVo profitList(SysOrderProfit vo, Integer rows, Integer page) {
        return sysTradeSummaryService.queryMchProfitList(vo, page, rows);
    }

    /**
     * 支付通道列表
     *
     * @param vo
     * @param rows
     * @param page
     * @return
     */
    @ResponseBody
    @PostMapping(value = "channelDataList")
    public JqGridVo channelDataList(SysAgentChannel vo, Integer rows, Integer page) {

        return sysChannelBiz.querydata(vo, page, rows);
    }

    /**
     * 代付通道列表
     *
     * @param vo
     * @param rows
     * @param page
     * @return
     */
    @ResponseBody
    @PostMapping(value = "paymentchannelDataList")
    public JqGridVo paymentchannelDataList(SysPaymentChannel vo, Integer rows, Integer page) {

        return sysPaymentChannelBiz.querydata(vo, page, rows);
    }


    /**
     * 查询代理商余额
     */
    @ResponseBody
    @PostMapping(value = "agentbalanceView")
    public ReturnData agentbalanceView(String mchId) {

        ReturnData returnData = new ReturnData();
        returnData.setCode(0);
        returnData.setMsg("查询成功");

        if (StringUtils.isBlank(mchId)) {
            returnData.setCode(1000);
            returnData.setMsg("商户编号不能为空");
            return returnData;
        }
        List<BalanceShowVo> showVos = proxyQueryBiz.queryBalance(mchId);
        returnData.setData(showVos);
        return returnData;
    }


    /**
     * 保存代理商
     */
    @ResponseBody
    @PostMapping(value = "saveAgent")
    public ResultEntity saveAgent(SysMerchant vo) {

        try {
            sysMerchBiz.saveAgent(vo);
            return ResultUtli.DEFAULT_SUCCESS("成功", null);
        } catch (ApiValidateException e) {
            e.printStackTrace();
            return ResultUtli.ERRO(10, e.getMessage(), null);
        }
    }

    /**
     * 为商户分配交易类型
     */
    @ResponseBody
    @GetMapping(value = "multiTradeType")
    public ResultEntity multiTradeType(@RequestParam("mchId") String mchId) {
        Map<String, Object> map = new HashMap<>();

        if (null == mchId) {
            return ResultUtli.SUCCESS(1000, "请求参数有误，请您稍后再试", null);
        }


        //获取所有的交易通道
        List<SysTradeType> tradeList = sysTradeTypeBiz.queryAllTradeType();
        //获取商户已有的交易通道
        List<SysTradeType> existTradeList = sysTradeTypeBiz.findTradeTypeByMchId(mchId);

        map.put("tradeList", tradeList);
        map.put("existTradeList", existTradeList);

        return ResultUtli.SUCCESS(0000, "成功", map);
    }

    /**
     * 获取商户已经选中的交易类型
     */
    @ResponseBody
    @GetMapping(value = "getSelectTradeType")
    public ResultEntity getSelectTradeType(@RequestParam(value = "mchId") String mchId) {
        List<SysTradeType> tradeList = sysTradeTypeBiz.findTradeTypeByMchId(mchId);
        return ResultUtli.SUCCESS(0000, "成功", tradeList);
    }

    /**
     * 设置交易类型
     *
     * @param tradeType
     * @return
     */
    @ResponseBody
    @PostMapping(value = "addChannelSet")
    public ResultEntity addChannelSet(SysTradeType tradeType) {
        //校验业务类型是否存在
        boolean isexist = sysChannelAttrBiz.isExistChannel(tradeType.getTradeType());
        if (!isexist) {
            return ResultUtli.ERRO(10, "该业务类型不存在，请重试！", null);
        }
        //校验业务类型是否重复
        boolean isexisttrade = sysTradeTypeBiz.isExist(tradeType);
        if (isexisttrade) {
            return ResultUtli.ERRO(10, "该业务类型已存在，请重试！", null);
        }
        sysTradeTypeBiz.addTradeType(tradeType);
        return ResultUtli.DEFAULT_SUCCESS("成功", null);
    }

    /**
     * 分配交易类型
     */
    @ResponseBody
    @PostMapping(value = "setAgentChannel")
    public ResultEntity setAgentChannel(@RequestParam("channelIds") String channelIds, TradeTypeVo vo) {

        try {
//            if( StringUtils.isEmpty(channelIds)){
//                return ResultUtli.ERRO(10,"请您给代理商选择支付通道",null);
//            }
            sysTradeTypeBiz.saveTradeType(channelIds, vo);
            return ResultUtli.DEFAULT_SUCCESS("成功", null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtli.ERRO(10, e.getMessage(), null);
        }

    }


    /**
     * 查询代理商的交易通道
     *
     * @param agentId
     * @return
     */
    @ResponseBody
    @GetMapping(value = "queryAgentChannel")
    public ReturnData queryAgentChannel(@RequestParam(value = "agentId") String agentId) {
        List<SysAgentChannel> agentChannelList = null;
        ReturnData returnData = new ReturnData();
        returnData.setCode(0);
        returnData.setMsg("");
        try {
            agentChannelList = sysChannelBiz.queryByAgentId(agentId);
            returnData.setData(agentChannelList);
            returnData.setCount(agentChannelList.size());
            return returnData;
        } catch (Exception e) {
            e.printStackTrace();
            returnData.setCode(10);
            returnData.setMsg("查询失败");
            return returnData;
        }
    }


    @ResponseBody
    @RequestMapping(value = "exportExcle")
    public void exportExcle(SysTrade vo, HttpServletResponse response) throws Exception {

        JqGridVo jqGridVo = orderService.queryOrderByUserId(vo, 1, 100000);
        List<?> rows1 = jqGridVo.getRows();

        ExportParams exportParams = new ExportParams("订单列表", "订单列表 ", ExcelType.XSSF);

        Workbook sheets = ExcelExportUtil.exportExcel(exportParams, SysTrade.class, rows1);

        ServletOutputStream outputStream = response.getOutputStream();

        response.setContentType("application/x-msdownload");
        response.setHeader("Content-Disposition", "attachment; filename="
                + URLEncoder.encode("boss_" + new SimpleDateFormat("yyyyMMdd").format(new Date()) + ".xlsx", "UTF-8"));

        sheets.write(outputStream);
        outputStream.close();

        sheets.close();

    }


    @ResponseBody
    @RequestMapping(value = "paymentexportExcle")
    public void exportExcle(SysPayment vo, HttpServletResponse response) throws Exception {


        JqGridVo jqGridVo = payMentBiz.queryOrderByUserId(vo, 1, 999999999);
        List<?> rows1 = jqGridVo.getRows();

        ExportParams exportParams = new ExportParams("代付列表", "代付列表 ", ExcelType.XSSF);

        Workbook sheets = ExcelExportUtil.exportExcel(exportParams, SysPayment.class, rows1);

        ServletOutputStream outputStream = response.getOutputStream();

        response.setContentType("application/x-msdownload");
        response.setHeader("Content-Disposition", "attachment; filename="
                + URLEncoder.encode("bosspayent_" + new SimpleDateFormat("yyyyMMdd").format(new Date()) + ".xlsx", "UTF-8"));

        sheets.write(outputStream);


        sheets.close();

    }

    /**
     * 同步上游代付结果
     */
    @ResponseBody
    @GetMapping(value = "syncUpChannel")
    public ReturnData syncUpChannel(@RequestParam(value = "orderNo") String orderNo) {
        ReturnData returnData = new ReturnData();
        returnData.setCode(0);

        try {
            SysPayment vo = payMentBiz.queryPaymentByOrderId(orderNo);
            proxyQueryBiz.syncUpChannel(vo);

            returnData.setMsg("同步成功");
        } catch (Exception e) {
            e.printStackTrace();
            returnData.setCode(10);
            returnData.setMsg("同步失败");
            return returnData;
        }
        return returnData;
    }


    /**
     * 更新支付通道状态
     */
    @ResponseBody
    @PostMapping(value = "updateChannelStatus")
    public ReturnData updateChannelStaus(SysAgentChannel vo) {
        ReturnData returnData = new ReturnData();
        returnData.setCode(0);

        try {

            /*if (!"00000002".equals(vo.getMchId())) {
                returnData.setCode(10);
                returnData.setMsg("只能操作测试代理商[00000002]");
                return returnData;
            }*/

            if (1 == vo.getStatus()) {
                vo.setStatus(0);
                returnData.setMsg("禁用成功");
            } else if (0 == vo.getStatus()) {
                vo.setStatus(1);
                returnData.setMsg("启用成功");
            }
            if ("undefined".equals(vo.getService())) {
                vo.setService("");
            }
            sysChannelBiz.updateChannelStatus(vo);
        } catch (Exception e) {
            e.printStackTrace();
            returnData.setCode(10);
            returnData.setMsg("操作失败");
        }
        return returnData;
    }

    /**
     * 更新代付通道状态
     */
    @ResponseBody
    @PostMapping(value = "updatePaymentChannelStatus")
    public ReturnData updatePaymentChannelStatus(SysPaymentChannel vo) {
        ReturnData returnData = new ReturnData();
        returnData.setCode(0);

        try {
            /*if (!"00000002".equals(vo.getMchId())) {
                returnData.setCode(10);
                returnData.setMsg("只能操作测试代理商[00000002]");
                return returnData;
            }*/

            if (1 == vo.getStatus()) {
                vo.setStatus(0);
                returnData.setMsg("禁用成功");
            } else if (0 == vo.getStatus()) {
                vo.setStatus(1);
                returnData.setMsg("启用成功");
            }
            if ("undefined".equals(vo.getService())) {
                vo.setService("");
            }
            sysPaymentChannelBiz.updatePaymentChannelStatus(vo);
        } catch (Exception e) {
            e.printStackTrace();
            returnData.setCode(10);
            returnData.setMsg("操作失败");
        }
        return returnData;
    }


    /**
     * 代付
     *
     * @return
     */
    @ResponseBody
    @PostMapping(value = "dfManage")
    public ReturnData dfManage(PaymentVo vo) {

        ReturnData returnData = new ReturnData();
        try {
            String yyyyMMddHHmmss = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());

            Map<String, String> objectObjectHashMap = new TreeMap<>();
            objectObjectHashMap.put("mch_id", "00000002");
            objectObjectHashMap.put("out_trade_no", IdGenerator.INSTANCE.nextId());
            objectObjectHashMap.put("account_name", vo.getAccount_name());
            objectObjectHashMap.put("bank_card", vo.getBank_card());
            objectObjectHashMap.put("bank_linked", vo.getBank_linked());
            objectObjectHashMap.put("trans_money", NumberHelpler.money2cent(vo.getTrans_money()).toString());
            objectObjectHashMap.put("bank_name", vo.getBank_name());
            objectObjectHashMap.put("bankBranchname", vo.getBankBranchname());
            objectObjectHashMap.put("bankProvince", vo.getBankProvince());
            objectObjectHashMap.put("bankCity", vo.getBankCity());
            objectObjectHashMap.put("bankCode", vo.getBankCode());
            objectObjectHashMap.put("service", vo.getService());
            //非必传
            if (StringUtils.isNotBlank(vo.getIdcard())) {
                objectObjectHashMap.put("idcard", vo.getIdcard());
            }
            if (StringUtils.isNotBlank(vo.getPhoneNo())) {
                objectObjectHashMap.put("phoneNo", vo.getPhoneNo());
            }

            String sign = SignUtils.map2signkey(objectObjectHashMap, "312f04f99be9e857bfb2c033eeb1d3e2");
            objectObjectHashMap.put("sign", sign);


            String s = HttpHelper.doPostForm("http://103.243.182.195/cspay/api/v1/dftransRequest", objectObjectHashMap);
            Map<String, String> map = new Gson().fromJson(s, Map.class);

            String ret_code = map.get("ret_code");
            if ("SUCCESS".equalsIgnoreCase(ret_code)) {
                returnData.setCode(0);
                returnData.setMsg("请求成功");
            } else {
                String ret_message = map.get("ret_message");
                returnData.setCode(10);
                returnData.setMsg(ret_message);
            }
        } catch (Exception e) {
            e.printStackTrace();
            returnData.setCode(10);
            returnData.setMsg("请求失败");
            return returnData;
        }
        return returnData;
    }

    /**
     * 批量代付
     *
     * @param
     * @return
     */
    @ResponseBody
    @PostMapping(value = "batchDfManage")
    public ReturnData batchDfManage(String service, String filePath) {
        ReturnData returnData = new ReturnData();

        try {
            if (StringUtils.isBlank(filePath)) {
                returnData.setCode(10);
                returnData.setMsg("请先上传excel文件");
                return returnData;
            }

            //读取指定文件路径的内容
            List<CardInfoVo> list = FileUtil.readxls(filePath);

            if (null == list || list.size() == 0) {
                returnData.setCode(10);
                returnData.setMsg("excel文件内容为空，请重新上传");
                return returnData;
            }

            for (CardInfoVo vo : list) {
                Map<String, String> objectObjectHashMap = new TreeMap<>();
                objectObjectHashMap.put("mch_id", "00000002");
                objectObjectHashMap.put("out_trade_no", IdGenerator.INSTANCE.nextId());
                objectObjectHashMap.put("account_name", vo.getAccountName());
                objectObjectHashMap.put("bank_card", vo.getCardNo());
                objectObjectHashMap.put("bank_linked", vo.getBankLinked());
                objectObjectHashMap.put("trans_money", NumberHelpler.money2cent(vo.getMoney()).toString());
                objectObjectHashMap.put("bank_name", vo.getBankName());
                objectObjectHashMap.put("bankBranchname", vo.getBranchName());
                objectObjectHashMap.put("bankProvince", vo.getProvince());
                objectObjectHashMap.put("bankCity", vo.getCity());
                objectObjectHashMap.put("bankCode", vo.getBankCode());
                objectObjectHashMap.put("service", service);

                String sign = SignUtils.map2signkey(objectObjectHashMap, "312f04f99be9e857bfb2c033eeb1d3e2");
                objectObjectHashMap.put("sign", sign);


                String s = HttpHelper.doPostForm("http://103.243.182.195/cspay/api/v1/dftransRequest", objectObjectHashMap);
                Map<String, String> map = new Gson().fromJson(s, Map.class);

                String ret_code = map.get("ret_code");
                if ("SUCCESS".equalsIgnoreCase(ret_code)) {
                    returnData.setCode(0);
                    returnData.setMsg("请求成功");
                } else {
                    String ret_message = map.get("ret_message");
                    returnData.setCode(10);
                    returnData.setMsg(ret_message);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            returnData.setCode(10);
            returnData.setMsg("请求失败");
            return returnData;
        }
        return returnData;
    }


    public String getAgentSignKey(String mch_id) {
        ValueOperations<String, String> stringStringValueOperations = stringRedisTemplate.opsForValue();
        String s = stringStringValueOperations.get("signkey:" + mch_id);
        return s;
    }


}
